package cn.tedu._07weibo.base.interceptors;

import cn.tedu._07weibo.pojo.vo.UserLoginVO;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.servlet.http.HttpSession;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.servlet.HandlerInterceptor;
@Slf4j
public class LoginCheckInterceptor implements HandlerInterceptor {

    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
         log.debug("进入登录状态拦截器...");
         HttpSession session=request.getSession();
        UserLoginVO loginVO=(UserLoginVO)session.getAttribute("user");
        if (loginVO!=null){
            response.sendRedirect("/login.html");
            return false;
        }
        return true;

    }
}
